package com.smart.controller.sys;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import com.smart.util.Page;
import com.smart.util.ExportExcelUtils;
import com.smart.util.Messages;
import com.smart.util.Pageable;
import com.smart.entity.SsWork;
import javax.annotation.Resource;
import lombok.AllArgsConstructor;
import io.swagger.annotations.Api;
import com.smart.vo.sys.SsWorkExcelVo;
import com.smart.entity.SysDictDetail;
import com.smart.service.SsWorkService;

import io.swagger.annotations.ApiOperation;
import com.smart.controller.BaseController;
import javax.servlet.http.HttpServletResponse;
import com.smart.service.SysDictDetailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020年6月11日 上午11:30:57
 * Copyright (C) 深圳工勘科技
 * @说明: 作业管理
 **/
@AllArgsConstructor
@RestController("sysSsWorkController")
@RequestMapping("/sys/sswork")
@Api(value="sswork",tags="作业管理")
public class SsWorkController extends BaseController{

	@Resource
	private SysDictDetailService sysddService;
	@Resource
	private SsWorkService ssworkServcie;
	
	@ApiOperation(value="Sys => 获取作业管理类型列表",notes="获取作业管理类型列表")
	@GetMapping(value="/car_type_list")
	public Messages<List<SysDictDetail>> sysDictDetailList(){
		List<SysDictDetail> list=sysddService.selectDictDataByType("ss_car_type");
		return Messages.success(list);
	}
	
	@GetMapping(value="/page")
	@ApiOperation(value="Sys => 获取巡查历史列表",notes="Sys获取巡查记录列表")
	public Messages<Page<SsWork>> page(String carno,String pileno,
			String name,String workTime_start,String workTime_end,Pageable pageable){
		Map<String,String> search = new HashMap<>();
		search.put("carno", carno);
		search.put("pileno", pileno);
		search.put("name", name);
		search.put("workTime_start", workTime_start);
		search.put("workTime_end", workTime_end);
		pageable.setSearch(search);
		return Messages.success(ssworkServcie.findPage(pageable));
	}
	
	/**
	 * @param res
	 * @return 导出所有数据
	 **/
	@GetMapping(value="/export_excel")
    public void exportExcel(HttpServletResponse res){
		List<SsWork> list = ssworkServcie.findAll();
		List<SsWorkExcelVo> voList = new ArrayList<>();
		if(list!=null){
			for(SsWork work : list){
				SsWorkExcelVo vo=new SsWorkExcelVo();
				vo.setCarNo(work.getCarNo());
				vo.setCreateTime(work.getCreateTime());
				vo.setName(work.getName());
				vo.setNo(work.getNo());
				vo.setPileNo(work.getPileNo());
				vo.setRockStratum(work.getRockStratum());
				vo.setSoilLayer(work.getSoilLayer());
				vo.setWorkTime(work.getWorkTime());
				voList.add(vo);
			}
		}
		String title = "作业记录.xlsx";
        String[] rowName={"作业编号","所属车辆设备","土层打入","岩层打入","桩编号","任务所属日期","任务提交时间","司机姓名"};
        List<Object> datalist = new ArrayList<>(1);
        datalist.addAll(voList);
        ExportExcelUtils.exportExcel(res,title,rowName,datalist);
	}
	
}